#include <iostream>
#include <vector>

using namespace std;

// https://leetcode.cn/contest/weekly-contest-453/problems/transform-array-to-all-equal-elements/
// Q1. 数组元素相等转换

class Solution
{
public:
    bool f(vector<int> &nums, int k)
    {
        for (int i = 0; i < nums.size(); i++)
        {
            if (nums[i] == 1)
            {
                if (i == (nums.size() - 1))
                {
                    return false;
                }
                nums[i] = -1;
                nums[i + 1] = -nums[i + 1];

                k--;
            }
            if (k < 0)
                return false;
        }
        return true;
    }
    bool canMakeEqual(vector<int> &nums, int k)
    {
        int temp = k;
        vector<int> nums1 = nums;
        for (int i = 0; i < nums.size(); i++)
        {
            if (nums[i] == -1)
            {
                if (i == (nums.size() - 1))
                {
                    return false || f(nums1, temp);
                }
                nums[i] = 1;
                nums[i + 1] = -nums[i + 1];

                k--;
            }
            if (k < 0)
                return false || f(nums1, temp);
        }
        return true;
    }
};
int main()
{
    Solution solution{};
    vector<int> nums{
        1,
        1,
        -1,
        -1,
        -1,
        1,
        1,
        1,
        1,
        1,
        1,
    };
    cout << solution.canMakeEqual(nums, 5) << endl;
    return 0;
}